









<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>iBaGuice - Caching</title>
    <link rel="stylesheet" href="./css/maven-theme.css" type="text/css" />
    <link rel="stylesheet" href="./css/maven-base.css" type="text/css"/>
    <link rel="stylesheet" href="./css/prettify.css" type="text/css"/>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
    <script type="text/javascript" src="./js/prettify.js"></script>
    <script type="text/javascript" src="./js/niftycube.js"></script>
    <script type="text/javascript">
        window.onload=function() {
            Nifty("div\#wrapper", "big");
            Nifty("div#breadcrumbs", "small");
            Nifty("div\#navcolumn", "small");
            Nifty("div.source", "medium");
            prettyPrint();
        }
    </script>
          <meta name="author" content="The iBaGuice Team" />
          </head>
  <body>
    <div id="wrapper">
        <div id="banner">
                      <a href="http://ibaguice.googlecode.com/svn/site/1.0-beta-1/index.html" id="bannerLeft"  >
    
                                            <img src="images/logo.png" alt="iBaGuice: enjoy the power of iBatis + Google Guice" />
    
            </a>
                            <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="breadcrumbs">
              
  

  
    
            
  
    
            <div class="xleft">
        <span id="publishDate">Last Published: 2010-02-10</span>
                  &nbsp;| <span id="projectVersion">Version: 1.0-beta-1</span>
                      </div>
                <div class="xright">      
  

  
    
            
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="leftColumn">
          <div id="navcolumn">
               
  

  
    
            
  
    
                       <h5>iBaGuice - Main</h5>
            <ul>
              
    <li class="none">
                    <a href="index.html">Introduction</a>
          </li>
              
    <li class="none">
                    <a href="core.html">The Core components</a>
          </li>
              
    <li class="none">
                    <a href="dao.html">The DAO Module</a>
          </li>
          </ul>
              <h5>Data Sources</h5>
            <ul>
              
    <li class="none">
                    <a href="datasource.html#Unpooled_Data_Source_Provider">Unpooled Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Pooled_Data_Source_Provider">Pooled Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#JNDI_Data_Source_Provider">JNDI Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Basic_Data_Source_Provider">Basic Data Source Provider</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Shared_Pool_Data_Source">Shared Pool Data Source</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Per_User_Pool_DataSource">Per User Pool DataSource</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#Connection_Pool_Data_Source_driver_adapter">Connection Pool Data Source driver adapter</a>
          </li>
              
    <li class="none">
                    <a href="datasource.html#C3P0_Provider">C3P0 Provider</a>
          </li>
          </ul>
              <h5>Caching support</h5>
            <ul>
              
    <li class="none">
                    <a href="caching.html#Ehcache">Ehcache</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#Hazelcast">Hazelcast</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#JBoss_Cache">JBoss Cache</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#Memcached">Memcached</a>
          </li>
              
    <li class="none">
                    <a href="caching.html#OSCache">OSCache</a>
          </li>
          </ul>
              <h5>Miscellaneous</h5>
            <ul>
              
    <li class="none">
                    <a href="stats.html">Project stats</a>
          </li>
              
    <li class="none">
                    <a href="iBaGuice-1.0-beta-1.pdf">PDF Manual</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
                    
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
              
        <li class="collapsed">
                    <a href="project-info.html">Project Information</a>
                </li>
              
                
                    
                  
                  
                  
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
              <h5>Modules</h5>
            <ul>
              
    <li class="none">
                    <a href="ibaguice-core/index.html">Core</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-dao/index.html">DAO</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-c3p0/index.html">c3p0</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-dbcp/index.html">Apache DBCP</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-oscache/index.html">OSCache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-memcached/index.html">Memcached</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-ehcache/index.html">Ehcache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-jbosscache/index.html">JBoss Cache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-hazelcast/index.html">Hazelcast Cache</a>
          </li>
              
    <li class="none">
                    <a href="ibaguice-samples/index.html">Samples</a>
          </li>
          </ul>
              <h5>External Links</h5>
            <ul>
              
    <li class="none">
                    <a href="">Project Page</a>
          </li>
              
    <li class="none">
                    <a href="http://ibatis.apache.org/" class="externalLink">iBatis</a>
          </li>
              
    <li class="none">
                    <a href="../google-guice/">Google Guice</a>
          </li>
          </ul>
                                               <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img class="poweredBy"
                 alt="Built by Maven"
                 src="./images/logos/maven-feather.png"
                 width="90"
                 height="30"
                 border="1" />
          </a>
                           
  

  
    
            
  
    
            </div>
        </div>
        <div id="bodyColumn">
          <div id="contentBox">
            <div class="section"><h2>Caching support</h2>
<p>Even if not strictly related to <i>google-guice</i> (users don't need the ibaguice core module) <i>iBaGuice</i> provides a caching support for three well known caching solutions:</p>
<ul><li><a href="http://ehcache.org/" class="externalLink">Ehcache</a>;</li>
<li><a href="http://www.hazelcast.com/" class="externalLink">Hazelcast</a>;</li>
<li><a href="http://www.jboss.org/jbosscache/" class="externalLink">JBoss Cache</a>;</li>
<li><a href="http://www.opensymphony.com/oscache/" class="externalLink">OSCache</a>;</li>
<li><a href="http://memcached.org/" class="externalLink">Memcached</a>.</li>
</ul>
<div class="section"><h3><a name="Ehcache">Ehcache</a></h3>
<p>Ehcache is a widely used java distributed cache for general purpose caching, Java EE and light-weight containers.</p>
<p>The <i>Ehcache</i> solution is built on top of the <i>ehcache-core</i> and comes without any <i>Ehcache</i> 3rd part applications. Please refeer to official <i>Ehcache</i> documentation if you need plugins.</p>
<p>Users that want to use <i>Ehcache</i> into their applications, first have to add in the <tt>pom.xml</tt> the following dependency:</p>
<div class="source"><pre>&lt;dependencies&gt;
    ...
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.ibaguice.cache&lt;/groupId&gt;
        &lt;artifactId&gt;ibaguice-ehcache&lt;/artifactId&gt;
        &lt;version&gt;XX.XX&lt;/version&gt;
    &lt;/dependency&gt;
    ...
&lt;/dependencies&gt;</pre>
</div>
<p>then, just configure it in the mapper XML:</p>
<div class="source"><pre>&lt;mapper namespace=&quot;com.google.code.ibaguice.ContactMapper&quot;&gt;

    &lt;cache type=&quot;com.google.code.ibaguice.cache.ehcache.EhcacheCache&quot;/&gt;

    ...

&lt;/mapper&gt;</pre>
</div>
<p>Users that need to configure <i>Ehcache</i> through XML configuration file, have to put in the classpath the <tt>/ehcache.xml</tt> resource; please refeer to the official <i>Ehcache</i> <a href="http://ehcache.org/documentation/configuration.html" class="externalLink">documentation</a> to know more details.</p>
<p><b>Note</b>: if the <tt>/ehcache.xml</tt> resource is not found or something goes wrong while loading it, the default configuration will be used.</p>
</div>
<div class="section"><h3><a name="Hazelcast">Hazelcast</a></h3>
<p>Hazelcast is an open source clustering and highly scalable data distribution platform for Java.</p>
<p>Users that want to use <i>Hazelcast</i> into their applications, first have to add in the <tt>pom.xml</tt> the following dependency:</p>
<div class="source"><pre>&lt;dependencies&gt;
    ...
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.ibaguice.cache&lt;/groupId&gt;
        &lt;artifactId&gt;ibaguice-hazelcast&lt;/artifactId&gt;
        &lt;version&gt;XX.XX&lt;/version&gt;
    &lt;/dependency&gt;
    ...
&lt;/dependencies&gt;</pre>
</div>
<p>then, just configure it in the mapper XML:</p>
<div class="source"><pre>&lt;mapper namespace=&quot;com.google.code.ibaguice.ContactMapper&quot;&gt;

    &lt;cache type=&quot;com.google.code.ibaguice.cache.ehcache.HazelcastCache&quot;/&gt;

    ...

&lt;/mapper&gt;</pre>
</div>
<p>Please refeer to the official <i>Hazelcast</i> <a href="http://code.google.com/docreader/#p=hazelcast&amp;s=hazelcast&amp;t=Introduction" class="externalLink">documentation</a> to know more details about the configuraion.</p>
</div>
<div class="section"><h3><a name="JBoss_Cache">JBoss Cache</a></h3>
<p>JBoss Cache's goal is to provide enterprise-grade clustering solutions to Java-based frameworks, application servers or custom-designed Java SE applications.</p>
<p>The <i>JBoss Cache</i> solution is built on top of the <i>jbosscache-core</i>.</p>
<p>Users that want to use <i>JBoss Cache</i> into their applications, first have to add in the <tt>pom.xml</tt> the following dependency:</p>
<div class="source"><pre>&lt;dependencies&gt;
    ...
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.ibaguice.cache&lt;/groupId&gt;
        &lt;artifactId&gt;ibaguice-jbosscache&lt;/artifactId&gt;
        &lt;version&gt;XX.XX&lt;/version&gt;
    &lt;/dependency&gt;
    ...
&lt;/dependencies&gt;</pre>
</div>
<p>then, just configure it in the mapper XML:</p>
<div class="source"><pre>&lt;mapper namespace=&quot;com.google.code.ibaguice.ContactMapper&quot;&gt;

    &lt;cache type=&quot;com.google.code.ibaguice.cache.jbosscache.JBossCache&quot;/&gt;

    ...

&lt;/mapper&gt;</pre>
</div>
<p>Users that need to configure <i>JBoss Cache</i> through XML configuration file, have to put in the classpath the <tt>/jboss-cache.xml</tt> resource; please refeer to the official <i>JBoss Cache</i> <a href="http://www.jboss.org/jbosscache/" class="externalLink">documentation</a> to know more details.</p>
<p><b>Note</b>: if the <tt>/jboss-cache.xml</tt> resource is not found or something goes wrong while loading it, the default configuration will be used.</p>
</div>
<div class="section"><h3><a name="Memcached">Memcached</a></h3>
<p>Memcached is a free &amp; open source, high-performance, distributed memory object caching system originally developed by Brad Fitzpatrick.</p>
<p>The Memcached solution relies on the memcached <a href="http://code.google.com/p/spymemcached/" class="externalLink">client</a> written by Dustin Sallings and using it is simple like using OSCache; first of all add in the <tt>pom.xml</tt> the following dependency:</p>
<div class="source"><pre>&lt;dependencies&gt;
    ...
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.ibaguice.cache&lt;/groupId&gt;
        &lt;artifactId&gt;ibaguice-memcached&lt;/artifactId&gt;
        &lt;version&gt;XX.XX&lt;/version&gt;
    &lt;/dependency&gt;
    ...
&lt;/dependencies&gt;</pre>
</div>
<p>then, just configure it in the mapper XML:</p>
<div class="source"><pre>&lt;mapper namespace=&quot;com.google.code.ibaguice.ContactMapper&quot;&gt;

    &lt;cache type=&quot;com.google.code.ibaguice.cache.memcached.MemcachedCache&quot;/&gt;

    ...

&lt;/mapper&gt;</pre>
</div>
<p>Obviously, the Memcached-based cache is configurable by putting the <tt>/memcached.properties</tt> classpath resource; if not found, the client will use the default setting. The following table resumes the supported configurations params; each parameter is optional, if not found in the configuration, the client will use the default value:</p>
<table class="bodyTable"><tbody><tr class="a"><th align="left">Property</th>
<th align="center">Default</th>
<th align="center">Description</th>
</tr>
<tr class="b"><td align="left">com.google.code.ibaguice.memcached.keyprefix</td>
<td align="center"><tt>_ibaguice_</tt></td>
<td align="center">any string identifier</td>
</tr>
<tr class="a"><td align="left">com.google.code.ibaguice.memcached.servers</td>
<td align="center"><tt>localhost:11211</tt></td>
<td align="center">space separated list of <tt>${host}:${port}</tt></td>
</tr>
<tr class="b"><td align="left">com.google.code.ibaguice.memcached.connectionfactory</td>
<td align="center"><tt>net.spy.memcached.DefaultConnectionFactory</tt></td>
<td align="center">Any class that implements <tt>net.spy.memcached.ConnectionFactory</tt></td>
</tr>
<tr class="a"><td align="left">com.google.code.ibaguice.memcached.expiration</td>
<td align="center">the number of seconds in 30 days</td>
<td align="center">the expiration time (in seconds)</td>
</tr>
<tr class="b"><td align="left">com.google.code.ibaguice.memcached.asyncget</td>
<td align="center">false</td>
<td align="center">flag to enable/disable the async get</td>
</tr>
<tr class="a"><td align="left">com.google.code.ibaguice.memcached.timeout</td>
<td align="center">5</td>
<td align="center">the timeout when using async get</td>
</tr>
<tr class="b"><td align="left">com.google.code.ibaguice.memcached.timeoutunit</td>
<td align="center"><tt>java.util.concurrent.TimeUnit.SECONDS</tt></td>
<td align="center">the timeout unit when using async get</td>
</tr>
<tr class="a"><td align="left">com.google.code.ibaguice.memcached.compression</td>
<td align="center">false</td>
<td align="center">if true, objects will be GZIP compressed before putting them to Memcached</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><h3><a name="OSCache">OSCache</a></h3>
<p>OSCache is a high performances caching solution developed and maintained by <a href="http://www.opensymphony.com/" class="externalLink">Open Symphony</a> and easily integrated in iBatis since the version 2.</p>
<p>Since iBatis 3 comes without it, and we strongly use it, we decided to reintroduce his use.</p>
<p>Using OSCache is easier than explain it, first of all add in the <tt>pom.xml</tt> the following dependency:</p>
<div class="source"><pre>&lt;dependencies&gt;
    ...
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.ibaguice.cache&lt;/groupId&gt;
        &lt;artifactId&gt;ibaguice-oscache&lt;/artifactId&gt;
        &lt;version&gt;XX.XX&lt;/version&gt;
    &lt;/dependency&gt;
    ...
&lt;/dependencies&gt;</pre>
</div>
<p>then, just configure it in the mapper XML:</p>
<div class="source"><pre>&lt;mapper namespace=&quot;com.google.code.ibaguice.ContactMapper&quot;&gt;

    &lt;cache type=&quot;com.google.code.ibaguice.cache.oscache.OSCache&quot;/&gt;

    ...

&lt;/mapper&gt;</pre>
</div>
<p>For proper OSCache configuration please read the offical <a href="http://wiki.opensymphony.com/display/CACHE/Configuration" class="externalLink">reference</a>.</p>
</div>
</div>

          </div>
        </div>
        <div class="clear">
          <hr/>
        </div>
        <div id="footer">
          <div class="xright">Copyright &#169;         
   
          2010.
    
      All Rights Reserved.    
  

  
    
            
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
    </div>
  </body>
</html>
